﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YieldKeyWord
{
    /// <summary>
    /// yield关键字:
    /// 只能使用yield return expression 和 yield break
    /// 使用yield return 返回一个枚举
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            foreach (int i in Power(2, 20))
            {
                Console.Write("{0} ", i);
            }
            Console.ReadKey();
        }

        public static IEnumerable Power(int number, int exponent)
        {
            int counter = 0;
            int result = 1;
            while (counter++ < exponent)
            {
                result = result + 2;;
                yield return result + 1;
            }
        }
    }
}
